<?php

namespace app\modules\Product\models;

use Yii;

/**
 * This is the model class for table "product_room_price".
 *
 * @property integer $id
 * @property integer $product_room_id
 * @property integer $people
 * @property string $price
 * @property string $inside_price
 * @property integer $user_id
 * @property string $created_at
 * @property string $updated_at
 */
class ProductRoomPrice extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'product_room_price';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['product_room_id', 'people'], 'required'],
            [['product_room_id', 'people', 'user_id'], 'integer'],
            [['price', 'inside_price'], 'number'],
            [['created_at', 'updated_at'], 'safe'],
        ];
    }


    // 保存前处理
    public function beforeSave($insert) {//{{{
        if($insert){
            $this->created_at = date("Y-m-d H:i:s");
            $this->user_id    = Yii::$app->user->id;
        }
    
        return parent::beforeSave($insert);
    }//}}}

    /** 获取对应的航线的舱房 **/
    public function getProductRoom(){
        return $this->hasOne(ProductRoom::className(), ['id' => 'product_room_id']);
    }
 



    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'product_room_id' => Yii::t('app', 'Product Room ID'),
            'people' => Yii::t('app', 'People'),
            'price' => Yii::t('app', 'Price'),
            'inside_price' => Yii::t('app', 'Inside Price'),
            'user_id' => Yii::t('app', 'User ID'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
        ];
    }
}
